home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Graphics_Utils / aMiPEG_1.1 / src / video.h < prev   
C/C++ Source or Header  |  1998-06-24  |  10KB  |  255 lines

  1.  
  2. #include <stdio.h>
  3. #include <setjmp.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. typedef int INT32;
  8. typedef short INT16;
  9. typedef char INT8;
  10. typedef unsigned int UINT32;
  11. typedef unsigned short UINT16;
  12. typedef unsigned char UINT8;
  13.  
  14. /* Define Parsing error codes. */
  15.  
  16. #define SKIP_PICTURE -10
  17. #define SKIP_TO_START_CODE -1
  18. #define PARSE_OK 1
  19.  
  20. /* Define BOOLEAN, TRUE, and FALSE. */
  21.  
  22. #define BOOLEAN int
  23. #define TRUE 1
  24. #define FALSE 0
  25.  
  26. /* Set ring buffer size. */
  27.  
  28. #define RING_BUF_SIZE 5
  29.  
  30. /* Macros for picture code type. */
  31.  
  32. #define I_TYPE 1
  33. #define P_TYPE 2
  34. #define B_TYPE 3
  35.  
  36. /* Start codes. */
  37.  
  38. #define SEQ_END_CODE 0x000001b7
  39. #define SEQ_START_CODE 0x000001b3
  40. #define GOP_START_CODE 0x000001b8
  41. #define PICTURE_START_CODE 0x00000100
  42. #define SLICE_MIN_START_CODE 0x00000101
  43. #define SLICE_MAX_START_CODE 0x000001af
  44. #define EXT_START_CODE 0x000001b5
  45. #define USER_START_CODE 0x000001b2
  46. #define SYSTEM_HEADER_START_CODE 0x000001bb 
  47. #define PACK_START_CODE 0x000001ba
  48. #define ISO_11172_END_CODE 0x000001b9
  49.  
  50. #define NOT_PACKET_ID ((unsigned char) 0xff)
  51. #define PACKET_START_CODE_MASK      0xffffff00
  52. #define PACKET_START_CODE_PREFIX    0x00000100
  53.  
  54. #define PACK_HEADER_SIZE 8
  55. #define MUX_RATE_SCALE_FACTOR 50
  56. #define STD_VIDEO_STREAM_ID ((unsigned char) 0xb9)
  57. #define STD_AUDIO_STREAM_ID ((unsigned char) 0xb8)
  58. #define RESERVED_STREAM_ID  ((unsigned char) 0xbc)
  59. #define PADDING_STREAM_ID   ((unsigned char) 0xbe)
  60. #define PRIVATE_STREAM_1_ID ((unsigned char) 0xbd)
  61. #define PRIVATE_STREAM_2_ID ((unsigned char) 0xbf)
  62. #define MIN_STREAM_ID_ID    ((unsigned char) 0xbc)
  63.  
  64. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  65.  
  66. #define MB_QUANTUM 100
  67.  
  68. /* Macros used with macroblock address decoding. */
  69.  
  70. #define MB_STUFFING 34
  71. #define MB_ESCAPE 35
  72.  
  73. /* Lock flags for pict images. */
  74.  
  75. #define DISPLAY_LOCK 0x01
  76. #define PAST_LOCK 0x02
  77. #define FUTURE_LOCK 0x04
  78.  
  79. #define GRAY_DITHER 6
  80. #define FULL_COLOR_DITHER 7
  81. #define CYBERGFX_DITHER 8
  82. #define CYBERGFXGRAY_DITHER 9
  83. #define CYBERGFXVLAYER_DITHER 10
  84. #define CYBERGFXVLAYERGRAY_DITHER 11
  85. #define PIV_DITHER 12
  86. #define NO_DITHER 13
  87.  
  88. /* Temporary definition of time stamp structure. */
  89.  
  90. typedef int TimeStamp;
  91.  
  92. /* Structure with reconstructed pixel values. */
  93.  
  94. typedef struct pict_image {
  95.   unsigned char *luminance;              /* Luminance plane.   */
  96.   unsigned char *Cr;                     /* Cr plane.          */
  97.   unsigned char *Cb;                     /* Cb plane.          */
  98.   unsigned char *display;                /* Display plane.     */
  99.   int locked;                            /* Lock flag.         */
  100.   TimeStamp show_time;                   /* Presentation time. */
  101. } PictImage;
  102.  
  103. /* Group of pictures structure. */
  104.  
  105. typedef struct GoP {
  106.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  107.   unsigned int tc_hours;                 /* Hour component of time code.   */
  108.   unsigned int tc_minutes;               /* Minute component of time code. */
  109.   unsigned int tc_seconds;               /* Second component of time code. */
  110.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  111.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  112.                         previous group of pictures.    */
  113.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  114.   char *ext_data;                        /* Extension data.                */
  115.   char *user_data;                       /* User data.                     */
  116. } GoP;
  117.  
  118. /* Picture structure. */
  119.  
  120. typedef struct pict {
  121.   unsigned int temp_ref;                 /* Temporal reference.             */
  122.   unsigned int code_type;                /* Frame type: P, B, I             */
  123.   unsigned int vbv_delay;                /* Buffer delay.                   */
  124.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  125.                         pixel values flag.              */
  126.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  127.   unsigned int forw_f;                   /* Used for vector decoding.       */
  128.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  129.                         pixel values flag.              */
  130.   unsigned int back_r_size;              /* Used in decoding.               */
  131.   unsigned int back_f;                   /* Used in decoding.               */
  132.   char *extra_info;                      /* Extra bit picture info.         */
  133.   char *ext_data;                        /* Extension data.                 */
  134.   char *user_data;                       /* User data.                      */
  135. } Pict;
  136.  
  137. /* Slice structure. */
  138.  
  139. typedef struct slice {
  140.   unsigned int vert_pos;                 /* Vertical position of slice. */
  141.   unsigned int quant_scale;              /* Quantization scale.         */
  142.   char *extra_info;                      /* Extra bit slice info.       */
  143. } Slice;
  144.  
  145. /* Macroblock structure. */
  146.  
  147. typedef struct macroblock {
  148.   int mb_address;                        /* Macroblock address.              */
  149.   int past_mb_addr;                      /* Previous mblock address.         */
  150.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  151.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  152.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  153.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  154.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  155.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  156.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  157.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  158.   unsigned int cbp;                      /* Coded block pattern.             */
  159.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  160.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  161.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  162.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  163.   int recon_right_for_prev;              /* Past right forw. vector.         */
  164.   int recon_down_for_prev;               /* Past down forw. vector.          */
  165.   int recon_right_back_prev;             /* Past right back vector.          */
  166.   int recon_down_back_prev;              /* Past down back vector.           */
  167. } Macroblock;
  168.  
  169. /* Block structure. */
  170.  
  171. typedef struct block {
  172.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  173.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  174.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  175.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  176. } Block;
  177.  
  178. /* Video stream structure. */
  179.  
  180. typedef struct vid_stream {
  181.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  182.   unsigned int v_size;                         /* Vert. size in pixels.      */
  183.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  184.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  185.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  186.   unsigned char picture_rate;                  /* Code for picture rate.     */
  187.   unsigned int bit_rate;                       /* Bit rate.                  */
  188.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  189.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  190. #if 0
  191.   unsigned char intra_quant_matrix[8*8];       /* Quantization matrix for
  192.                           intracoded frames.         */
  193.   unsigned char non_intra_quant_matrix[8*8];   /* Quanitization matrix for 
  194.                           non intracoded frames.     */
  195. #endif
  196.   char *ext_data;                              /* Extension data.            */
  197.   char *user_data;                             /* User data.                 */
  198.   GoP group;                                   /* Current group of pict.     */
  199.   Pict picture;                                /* Current picture.           */
  200.   Slice slice;                                 /* Current slice.             */
  201.   Macroblock mblock;                           /* Current macroblock.        */
  202.   Block block;                                 /* Current block.             */
  203.   int state;                                   /* State of decoding.         */
  204.   int bit_offset;                              /* Bit offset in stream.      */
  205.   unsigned int *buffer;                        /* Pointer to next byte in
  206.                           buffer.                    */
  207.   int buf_length;                              /* Length of remaining buffer.*/
  208.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  209.   int max_buf_length;                          /* Max lenght of buffer.      */
  210.   PictImage *past;                             /* Past predictive frame.     */
  211.   PictImage *future;                           /* Future predictive frame.   */
  212.   PictImage *current;                          /* Current frame.             */
  213.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  214.  
  215.   unsigned short *intra_quant_matrix_ptr[32];        /* Quantization matrix for intracoded frames.
  216.                                The zero entry is for security reason only.     */
  217.  
  218.   BOOLEAN non_intra_default;                /* default non_intra matrix is all 16 */
  219.   unsigned short *non_intra_quant_matrix_ptr[32];    /* Quantization matrix for non intracoded frames.*/
  220.  
  221.   BOOLEAN display_is_initialized;        /* Resize display still to be done */
  222. } VidStream;   
  223.  
  224. /* Declaration of global pointer to current video stream. */
  225.  
  226. extern VidStream *curVidStream;
  227.  
  228. /* Quiet mode flag. */
  229. extern int quietFlag;
  230.  
  231. /* Definition of Contant integer scale factor. */
  232.  
  233. #define CONST_BITS 13
  234.  
  235. /* Misc DCT definitions */
  236. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  237. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  238.  
  239. typedef short DCTELEM;
  240. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  241.  
  242.  
  243. extern double realTimeStart;
  244. extern int totNumFrames;
  245. extern int noDisplayFlag;
  246. extern jmp_buf env;
  247.  
  248. #ifdef ANALYSIS
  249. extern unsigned int bitCount;
  250. extern int showEachFlag;
  251. extern unsigned int cacheHit[8][8];
  252. extern unsigned int cacheMiss[8][8];
  253. #endif
  254.  
  255.